package com.lewei.view;

import java.awt.EventQueue;
import java.awt.HeadlessException;
import java.awt.Point;
import java.awt.Toolkit;

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.SwingWorker;

import java.awt.Font;

import javax.swing.JTextField;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.SwingConstants;

import com.lewei.dao.SqliteDao;
import com.lewei.excel.ExcelOL100;
import com.lewei.excel.ExcelCertificateNo;
import com.lewei.excel.ExcelOL25;
import com.lewei.excel.ExcelOL35;
import com.lewei.excel.ExcelOL35SCHINDLER;
import com.lewei.excel.ExcelOL35SCHINDLERCN;
import com.lewei.excel.ExcelPrintRule;
import com.lewei.excel.ExcelSGB;
import com.lewei.excel.ExcelSGB05;
import com.lewei.excel.ExcelSGB05CN;
import com.lewei.excel.ExcelSgbPrintRule;
import com.lewei.model.Adjustment;
import com.lewei.model.CertificateInfo;
import com.lewei.model.FRange;
import com.lewei.model.PrintInModel;
import com.lewei.model.RuleInfo;
import com.lewei.model.SgbRuleInfo;
import com.lewei.print.OL100;
import com.lewei.print.OL25;
import com.lewei.print.OL35;
import com.lewei.print.OL35CN;
import com.lewei.print.OL35SCHINDLER;
import com.lewei.print.OL35SCHINDLERCN;
import com.lewei.print.SGB02;
import com.lewei.print.SGB05;
import com.lewei.print.SGB05CN;
//import com.lewei.print.SGB05;
import com.lewei.utils.CodeAndPrint;
import com.lewei.utils.CodeGenerate;
import com.lewei.utils.Constants;
import com.lewei.utils.LOCALMAC;
import com.lewei.utils.SGBFRangeSet;
import com.lewei.utils.ToInterface;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;

import net.sf.json.JSONObject;
import net.sf.json.JSONArray;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;

/**
 * 主界面
 * 
 * @author 22901
 * 
 */

public class MainPrint extends JFrame {
	public String guideRail = "";

	public String getGuideRail() {
		return guideRail;
	}

	public void setGuideRail(String guideRail) {
		this.guideRail = guideRail;
	}

	/** 8位年月日 */
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private JPanel contentPane;
	// 表格
	private JTable tablelist;
	/** 出厂编号搜索框 */
	private JTextField textSerial;
	/** JTable数据头 */
	private String[] heads = { "客户名称", "定单号", "出厂编号", "物料号", "标签样式", "物料描述",
			"总数量" };
	/** JTable数据模型 */
	DefaultTableModel tableModel = new DefaultTableModel(null, heads);
	/** 文件选择器 */
	JFileChooser jfc = new JFileChooser();
	/** 打印 */
	private JButton btnPrint;
	/** 打印时间 */
	private JTextField textNewDate;
	/** 打印标签型号 */
	private JComboBox<String> comboBoxLabelType;
	/** 表列表model */
	private List<PrintInModel> list = null;
	/** 已经选择的行数 **/
	private int[] selectedRow = null;
	/** 打印机选择 */
	private JComboBox<String> printerSelector;
	private static DefaultComboBoxModel<String> aModel = new DefaultComboBoxModel<>();
	/** 打印数量 */
	private JTextField textNum;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LOCALMAC localmac =  new LOCALMAC();
//					//得到IP，输出PC-201309011313/122.206.73.83
//					InetAddress ia = InetAddress.getLocalHost();
//					String username = localmac.getLocalMac(ia);
//					String str =ToInterface.interfaceUtil("http://114.67.247.198:9090/demo-api/user/deadline", "username="+username+"");
//					System.out.println(str);   
//					String data = str.substring(90,114);
//					System.out.println("===" + data);
//					String strmodel="Thu May 07 23:59:19 CST 2015";
//			        SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.US);
//			        Date date = df.parse(data);  
//			        System.out.println("转换后的值：" + date);
					// 时间表示格式可以改变，yyyyMMdd需要写例如20160523这种形式的时间
					String endTime=new String("2099-6-6 18:22:22"); 
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					System.out.println("********1*********");
					Date sd1=df.parse(endTime);
			        System.out.println(endTime);
			        Date beginTime = new Date();
			        System.out.println(beginTime);
			        if(beginTime.before(sd1)){
			        	MainPrint frame = new MainPrint();
						frame.setVisible(true);
						setPrinterModel();
			        }else{
						JOptionPane.showMessageDialog(null, "未知错误");
						return;

			        }

//					MainPrint frame = new MainPrint();
//					frame.setVisible(true);
//					setPrinterModel();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * 设置打印机列表模型。
	 */
	private static void setPrinterModel() {
		// 构建打印请求属性集
		HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
		// 设置打印格式，因为未确定类型，所以选择autosense
		DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
		// 查找所有的可用的打印服务
		PrintService printService[] = PrintServiceLookup.lookupPrintServices(
				flavor, pras);
		String defaultPrinterName = getDefaultPrinter();
		String printerName = "";
		for (PrintService p : printService) {
			printerName = p.getName();
			if (defaultPrinterName.equals(printerName)) {
				aModel.setSelectedItem(printerName);
			}
			aModel.addElement(printerName);
		}
	}

	/**
	 * 获取默认打印机。
	 * 
	 * @return
	 */
	private static String getDefaultPrinter() {
		SqliteDao sd = new SqliteDao();
		String result = null;
		try {
			result = sd.getDefaultPrinterName();
		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, e.getMessage());
		}
		return result;
	}

	/**
	 * Create the frame.
	 */
	public MainPrint() {

		final JFrame frame = this;
		setResizable(false);
		// 设置图标
		setIconImage(Toolkit.getDefaultToolkit().getImage(
				MainPrint.class.getResource("/images/Wittur_Logo.gif")));
		// 设置标题
		setTitle("标签打印");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		double screenWidth = Toolkit.getDefaultToolkit().getScreenSize()
				.getWidth();
		double screenHeight = Toolkit.getDefaultToolkit().getScreenSize()
				.getHeight();
		setBounds((int) ((screenWidth - 700) / 2),
				(int) ((screenHeight - 350) / 2), 700, 350);
		contentPane = new JPanel();
		contentPane.setToolTipText("\u5927");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.setLayout(null);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(0, 83, 694, 186);
		contentPane.add(scrollPane);

		tablelist = new JTable();
		tablelist.setModel(new DefaultTableModel(new Object[][] {}, heads));
		scrollPane.setViewportView(tablelist);

		JLabel label_1 = new JLabel("\u5237\u65B0");
		label_1.setBounds(488, 21, 92, 19);
		label_1.setHorizontalAlignment(SwingConstants.CENTER);
		label_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO
				SqliteDao sd = new SqliteDao();
				String labelType = (String) comboBoxLabelType.getSelectedItem();
				if (labelType.equals("通力安全钳") || labelType.equals("通力安全钳中文")) {
					labelType = "SGB05";
				}
				if (labelType.equals("OL35迅达中文")
						|| labelType.equals("OL35迅达英文")) {
					labelType = "OL35SCHINDLER";
				}
				if (labelType.equals("迅达SGB")) {
					labelType = "SGB";
				}
				// if (labelType.equals("SGB05CN")) {
				// labelType = "SGB05";
				// }
				// if (labelType.equals("OL35SCHINDLERCN")) {
				// labelType = "OL35SCHINDLER";
				// }
				heads = sd.getTableHeads(labelType);
				System.out.println(labelType);
				File path = new File(sd.getPath(labelType));
				System.out.println("---------------" + labelType);
				System.out.println("数据库地址名称:" + labelType);
				if (!path.exists()) {
					JOptionPane.showMessageDialog(null, "未找到数据文件");
					return;
				}
				// 更新列表
				updateTableList(path);
			}
		});
		label_1.setForeground(new Color(255, 140, 0));
		label_1.setFont(new Font("宋体", Font.ITALIC, 13));
		contentPane.add(label_1);

		JLabel label_2 = new JLabel("\u578B   \u53F7 \uFF1A");
		label_2.setBounds(12, 7, 70, 21);
		label_2.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(label_2);

		comboBoxLabelType = new JComboBox<String>();
		comboBoxLabelType.setBounds(78, 7, 126, 21);
		comboBoxLabelType.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				// 如果选中了一个
				if (e.getStateChange() == ItemEvent.SELECTED) {
					// 这里写你的任务 ，比如取到现在的值
					String labelType = (String) comboBoxLabelType
							.getSelectedItem();
					if (labelType.equals("OL35证书标签")) {
						labelType = "OL35";
					} else if (labelType.equals("迅达SGB")) {
						labelType = "SGB";
					} else if (labelType.equals("通力安全钳")) {
						labelType = "SGB05";
					} else if (labelType.equals("通力安全钳中文")) {
						labelType = "SGB05";
					} else if (labelType.equals("OL35迅达英文")) {
						labelType = "OL35SCHINDLER";
					} else if (labelType.equals("OL35迅达中文")) {
						labelType = "OL35SCHINDLER";
					}
					SqliteDao sd = new SqliteDao();
					// 表头数据类型[]
					heads = sd.getTableHeads(labelType);
					// 列表更新
					// tableModel = new DefaultTableModel(null, heads);
					// tablelist.setModel(tableModel);
					// TODO
					File path = new File(sd.getPath(labelType));
					if (!path.exists()) {
						JOptionPane.showMessageDialog(null, "未找到数据文件");
						return;
					}
					// 更新列表
					updateTableList(path);
				}
			}
		});

		comboBoxLabelType.setModel(new DefaultComboBoxModel<String>(
				new String[] { "OL100", "OL35", "迅达SGB", "通力安全钳", "通力安全钳中文",
						"OL35迅达英文", "OL35迅达中文" }));// ,
		// comboBoxLabelType.setModel(new DefaultComboBoxModel<String>(
		// new String[] { "SGB" }));

		// comboBoxLabelType.setModel(new DefaultComboBoxModel<String>(new
		// String[] { "OL100", "OL25", "OL35", "SGB", "SGB05","SGB05CN",
		// "OL35SCHINDLER", "OL35SCHINDLERCN" }));
		comboBoxLabelType.setForeground(Color.BLACK);
		comboBoxLabelType.setFont(new Font("宋体", Font.ITALIC, 12));
		contentPane.add(comboBoxLabelType);

		JPanel panel = new JPanel();
		panel.setBounds(331, 50, 363, 37);
		panel.setForeground(Color.BLACK);
		panel.setBorder(new LineBorder(new Color(0, 0, 0)));
		contentPane.add(panel);
		panel.setLayout(null);

		JButton button_1 = new JButton("\u641C\u7D22");// 搜索
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (list == null || list.size() <= 0) {
					JOptionPane.showMessageDialog(null, "请先刷新数据！");
					return;
				}

				searchDataInList();
			}

		});
		button_1.setBounds(242, 10, 93, 23);
		panel.add(button_1);
		button_1.setFont(new Font("宋体", Font.PLAIN, 12));

		textSerial = new JTextField();
		textSerial.setBounds(75, 11, 126, 21);
		panel.add(textSerial);
		textSerial.setColumns(10);

		JLabel label_3 = new JLabel("\u51FA\u5382\u7F16\u53F7\uFF1A");// 出厂编号
		label_3.setBounds(10, 11, 70, 21);
		panel.add(label_3);
		label_3.setFont(new Font("宋体", Font.PLAIN, 12));

		JLabel label_4 = new JLabel("\u6253\u5370\u65E5\u671F\uFF1A");
		label_4.setBounds(224, 8, 70, 21);
		label_4.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(label_4);

		textNewDate = new JTextField();
		textNewDate.setBounds(283, 10, 126, 21);
		textNewDate.setToolTipText("\u6587\u4EF6\u76EE\u5F55");// 文件目录
		textNewDate.setText(Constants.NEWDATA);
		textNewDate.setForeground(Color.DARK_GRAY);
		textNewDate.setFont(new Font("宋体", Font.PLAIN, 11));
		textNewDate.setColumns(10);
		textNewDate.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				textNewDate.getText();
				Point p = new Point(300, 51);
				// JCalendarChooser chooser = new
				// JCalendarChooser(frame,"我的日期",p);
				// Calendar d = chooser.showCalendarDialog();
				// String monthstr=String.valueOf((d.get(Calendar.MONTH) + 1));
				// String daystr=String.valueOf(d.get(Calendar.DAY_OF_MONTH));
				// textNewDate.setText(d.get(Calendar.YEAR) + "-"+ monthstr +
				// "-"+ daystr);
				// 日期设置
				JDateChooser chooser = new JDateChooser(frame, "我的日期", p);
				String date = chooser.showCalendarDialog(textNewDate.getText()
						.trim());
				textNewDate.setText(date);
			}
		});

		contentPane.add(textNewDate);

		JButton btnAdjust = new JButton("\u8C03\u6574\u6807\u7B7E");
		btnAdjust.setBounds(10, 288, 93, 23);
		btnAdjust.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnAdjust.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// 打开标签位置调整界面
				AdjustLabelPositionView alpv = AdjustLabelPositionView
						.GetAdjustLabelPositionView();
				alpv.setVisible(true);
			}
		});
		btnAdjust.setOpaque(false);
		btnAdjust.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(btnAdjust);

		JButton btn_path = new JButton("\u8C03\u6574\u8DEF\u5F84");
		btn_path.setBounds(111, 288, 93, 23);
		btn_path.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btn_path.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				// 打开路径调整界面
				AdjustPathPositionView alpv = AdjustPathPositionView
						.GetAdjustLabelPositionView();
				alpv.setVisible(true);
			}
		});
		btn_path.setOpaque(false);
		btn_path.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(btn_path);

		JLabel label_6 = new JLabel("\u6253 \u5370 \u673A\uFF1A");
		label_6.setBounds(318, 292, 70, 15);
		label_6.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(label_6);

		printerSelector = new JComboBox<String>();
		printerSelector.setBounds(381, 289, 200, 21);
		printerSelector.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				if (e.getStateChange() == ItemEvent.SELECTED) {
					// 更改默认打印机
					SqliteDao sd = new SqliteDao();
					try {
						sd.setDefaultPrinterName(printerSelector
								.getSelectedItem().toString());
					} catch (Exception e1) {
						e1.printStackTrace();
						JOptionPane.showMessageDialog(null, e1.getMessage());
					}
				}
			}
		});
		printerSelector.setForeground(Color.BLACK);
		printerSelector.setFont(new Font("宋体", Font.ITALIC, 12));
		printerSelector.setModel(aModel);
		contentPane.add(printerSelector);

		btnPrint = new JButton("\u6253\u5370");
		btnPrint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		btnPrint.setBounds(592, 288, 80, 23);
		btnPrint.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (btnPrint.isEnabled()) {
					selectedRow = tablelist.getSelectedRows();

					if (selectedRow.length == 0) {
						JOptionPane.showMessageDialog(null, "请先选择要打印的记录！");
						return;
					}
					// 设置不可进行其他操作
					setUnableOperator();
					// 打印
					if (comboBoxLabelType.getSelectedItem().equals("OL100")) {
						goPrintOL100().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"OL35")) {
						goPrintOL35().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"OL25")) {
						goPrintOL25().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"迅达SGB")) {
						goPrintSGB().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"通力安全钳")) {
						goPrintSGB05().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"通力安全钳中文")) {
						goPrintSGB05CN().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"OL35迅达中文")) {
						goPrintOL35SCHINDLERCN().execute();
					} else if (comboBoxLabelType.getSelectedItem().equals(
							"OL35迅达英文")) {
						goPrintOL35SCHINDLER().execute();
					}
					// else
					// //
					// if(comboBoxLabelType.getSelectedItem().equals("OL35证书标签")){
					// // goPrintOL35CN().execute();
					// }

				}
			}
		});
		btnPrint.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(btnPrint);

		JLabel label = new JLabel("\u6570   \u91CF \uFF1A");
		label.setBounds(12, 38, 70, 21);
		label.setFont(new Font("宋体", Font.PLAIN, 12));
		contentPane.add(label);

		textNum = new JTextField();
		textNum.setBounds(78, 38, 126, 21);
		textNum.setToolTipText("\u6587\u4EF6\u76EE\u5F55");// 文件目录
		textNum.setText("1");
		textNum.setForeground(Color.DARK_GRAY);
		textNum.setFont(new Font("宋体", Font.PLAIN, 11));
		textNum.setColumns(10);
		contentPane.add(textNum);
	}

	/**
	 * 在集合中搜索数据
	 */
	private void searchDataInList() {
		String serial = (String) textSerial.getText().toString();
		List<PrintInModel> tempList = new ArrayList<PrintInModel>();
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).getSerialNo().contains(serial)) {
				tempList.add(list.get(i));
			}
		}
		if (tempList.size() == 0) {
			JOptionPane.showMessageDialog(null, "没有匹配的结果！");
			return;
		}
		if (list.size() > 0
				&& comboBoxLabelType.getSelectedItem().equals("通力安全钳")
				|| comboBoxLabelType.getSelectedItem().equals("通力安全钳中文")) {
			Object[][] data = new Object[tempList.size()][7];
			for (int i = 0; i < tempList.size(); i++) {
				data[i][0] = list.get(i).getElevator();
				data[i][1] = list.get(i).getSerialNo();
				data[i][2] = list.get(i).getItemCode();
				data[i][3] = list.get(i).getfMax();
				data[i][4] = list.get(i).getvMax();
				data[i][5] = list.get(i).getA();
				data[i][6] = list.get(i).getQuantity();
				// 列表更新
				tableModel = new DefaultTableModel(data, heads);
				tablelist.setModel(tableModel);
			}
		} else {
			Object[][] data = new Object[tempList.size()][10];
			for (int i = 0; i < tempList.size(); i++) {
				data[i][0] = tempList.get(i).getCustomer();
				data[i][1] = tempList.get(i).getOrderNo();
				data[i][2] = tempList.get(i).getSerialNo();
				data[i][3] = tempList.get(i).getItemCode();
				data[i][4] = tempList.get(i).getLabelType();
				data[i][5] = tempList.get(i).getItemDesc();
				data[i][6] = tempList.get(i).getQuantity();
				// 列表更新
				tableModel = new DefaultTableModel(data, heads);
				tablelist.setModel(tableModel);
			}
		}

	}

	/**
	 * 更新界面数据tablelist。
	 */
	private void updateTableList(File path) {
		// TODO Auto-generated method stub
		try {
			if (comboBoxLabelType.getSelectedItem().equals("OL100")) {
				list = ExcelOL100.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("OL35")
					|| comboBoxLabelType.getSelectedItem().equals("OL35证书标签")) {
				list = ExcelOL35.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("OL25")) {
				list = ExcelOL25.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("迅达SGB")) {
				list = ExcelSGB.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("通力安全钳")) {
				list = ExcelSGB05.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("通力安全钳中文")) {
				list = ExcelSGB05CN.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("OL35迅达中文")) {
				list = ExcelOL35SCHINDLERCN.readExcel(path);
			} else if (comboBoxLabelType.getSelectedItem().equals("OL35迅达英文")) {
				list = ExcelOL35SCHINDLER.readExcel(path);
			}
			if (list.size() > 0&& comboBoxLabelType.getSelectedItem().equals("SGB")) {
				Object[][] data = new Object[list.size()][7];
				for (int i = 0; i < list.size(); i++) {
					data[i][0] = list.get(i).getCustomer();
					data[i][1] = list.get(i).getOrderNo();
					data[i][2] = list.get(i).getSerialNo();
					data[i][3] = list.get(i).getOther();
					data[i][4] = list.get(i).getLabelType();
					data[i][5] = list.get(i).getItemDesc();
					data[i][6] = list.get(i).getQuantity();

					// 列表更新
					tableModel = new DefaultTableModel(data, heads);
					tablelist.setModel(tableModel);
				}
			} else if (list.size() > 0
					&& comboBoxLabelType.getSelectedItem().equals("通力安全钳")
					|| comboBoxLabelType.getSelectedItem().equals("通力安全钳中文")) {
				Object[][] data = new Object[list.size()][7];
				for (int i = 0; i < list.size(); i++) {

					list.get(i).getItemCode();
					data[i][0] = list.get(i).getElevator();
					data[i][1] = list.get(i).getSerialNo();
					data[i][2] = list.get(i).getItemCode();
					data[i][3] = list.get(i).getfMax();
					data[i][4] = list.get(i).getvMax();
					data[i][5] = list.get(i).getA();
					data[i][6] = list.get(i).getQuantity();

					// 列表更新
					tableModel = new DefaultTableModel(data, heads);
					tablelist.setModel(tableModel);
				}
			} else {
				Object[][] data = new Object[list.size()][7];
				for (int i = 0; i < list.size(); i++) {
					data[i][0] = list.get(i).getCustomer();
					data[i][1] = list.get(i).getOrderNo();
					data[i][2] = list.get(i).getSerialNo();
					data[i][3] = list.get(i).getItemCode();
					data[i][4] = list.get(i).getLabelType();
					data[i][5] = list.get(i).getItemDesc();
					data[i][6] = list.get(i).getQuantity();
					// 列表更新
					tableModel = new DefaultTableModel(data, heads);
					tablelist.setModel(tableModel);
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			JOptionPane
					.showMessageDialog(null, "读取Excel出错：\n" + e.getMessage());
			e.printStackTrace();

		}
	}

	/**
	 * 设置不可继续操作。
	 */
	private void setUnableOperator() {
		printerSelector.setEnabled(false);
		btnPrint.setEnabled(false);
	}

	/**
	 * 设置可继续操作。
	 */
	private void setEnableOperator() {
		printerSelector.setEnabled(true);
		btnPrint.setEnabled(true);

	}

	/**
	 * 子线程打印OL100标签。 80340
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintOL100() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL100 print = new OL100(printerSelector
								.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFT80340E = position.get(0)
									.getLeft();
							Constants.LABELTOP80340E = position.get(0).getTop();
							Constants.LABELLEFT80340 = position.get(1)
									.getLeft();
							Constants.LABELTOP80340 = position.get(1).getTop();

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F310", subSerianNo);
							print.setSerialNo(serialNo);
							
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getTypeNo(),
									"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");// 生成二维码图片
							// c.printDimensionalCode(print.getSerialNo(),
							// "C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");//
							// 生成一维码图片
							// c.printDimensionalCode(print.getTypeNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							print.setLabelType(p.getLabelType());
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private OL100 generateOtherInfo(OL100 print, PrintInModel p) {
				// TODO Auto-generated method stub
				// item=7T3BEG178L14SAAK
				String item = p.getItemCode().trim();
				/** 语言 */
				String lenFlag = item.substring(4, 5);
				/** 物料号五位之后 */
				String item1 = item.substring(5);
				/** 物料号G17 */
				String item2 = item.substring(5, 8);
				/**判断是轿厢还是对重的数值，偶数为对重，基数为轿厢*/
				String code=item.substring(6, 8);
				/** 左右 */
				String item3 = item.substring(9, 10);
				/** 提拉力 */
				String item4 = item.substring(10, 11);
				/** 鋼絲繩直徑 */
				String item5 = item.substring(8, 9);
				/** CAR */
				String technicalParameters = null;

				File file = new File(Constants.RULEPATH);
				try {

					List<RuleInfo> list = ExcelPrintRule.readExcel(file);
					 if(lenFlag.equals("U")||lenFlag.equals("Ts")){
						 for (int i = 0; i < list.size(); i++) {
								if (list.get(i).getType().equals(item2)&& list.get(i).getModelNo().equals("80340EN81-20")) {
									print.setVns(list.get(i).getVns());
									print.setVcs(list.get(i).getVcs());
									print.setVts(list.get(i).getVts());
									technicalParameters = list.get(i).getTechnicalParameters();
									} 
								}
					 	}else{
					 		for (int i = 0; i < list.size(); i++) {
					 			if (list.get(i).getType().equals(item2)&& list.get(i).getModelNo().equals("80340")) {
					 				print.setVns(list.get(i).getVns());
					 				print.setVcs(list.get(i).getVcs());
					 				print.setVts(list.get(i).getVts());
					 				technicalParameters = list.get(i).getTechnicalParameters();
					 				} 
					 			}
					 		}
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "規則匹配失敗！");
					e.printStackTrace();
				}

				String typeNo = null;
				if (lenFlag.equals("G")) {
					String type="";
					lenFlag.substring(1,lenFlag.length());
					//判断是对重还是轿厢用中文替换
					int value=Integer.parseInt(code);
					if(value%2==0){
						type="-对重-";
					}else{
						type="-轿厢-";
					}
					//判断是否是左右，用中文替换
					String LR=item3.equals("L")? "左":"右";
					typeNo = "80340" + item2+type+LR ;
				} else if(lenFlag.equals("T")){
					typeNo = "80340" + item1 + "-" + "CWT" + "-"
							+ item3;
				}else {
					typeNo = "80340" + item1 + "-" + technicalParameters + "-"
							+ item3;
				}
				String fbrakeMin = null;
				if (item4.equals("1")) {
					fbrakeMin = "1100";
				} else if (item4.equals("2")) {
					fbrakeMin = "2100";
				}
				String lineThickness = "error";
				if (item5.equals("1")) {
					lineThickness = "10.0";
				} else if (item5.equals("8")) {
					lineThickness = "8.0";
				} else if (item5.equals("6")) {
					lineThickness = "6.0";
				}
				file = new File(Constants.CERTIFICATEPATH);
				try {
					List<CertificateInfo> list = ExcelCertificateNo
							.readExcel(file);
					for (int i = 0; i < list.size(); i++) {

						if ((lenFlag.equals("G")
								&& list.get(i).getModelNo().equals("80340")
								&& list.get(i).getLineThickness()
										.equals(lineThickness) && list.get(i)
								.getVns().equals(print.getVns()))
								|| (lenFlag.equals("E") && list.get(i)
										.getModelNo().equals("80340E"))) {
							try {
								Date expDate = sdf.parse(list.get(i)
										.getExpireDate());
								Date date = new Date();
								if (expDate.getTime() <= date.getTime()) {
									JOptionPane.showMessageDialog(null,
											"证书已过期！");
									return null;
								} else {
									print.setCertificateNo(list.get(i)
											.getCertificateNo());
									print.setTestingAgency(list.get(i)
											.getTestingAgency());
								}
							} catch (ParseException e) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null, "证书匹配失敗！");
								e.printStackTrace();
							}
						} else {
							continue;
						}
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
				print.setLineThickness(lineThickness);
				print.setFbrakeMin(fbrakeMin);
				print.setTypeNo(typeNo);
				print.setLenFlag(lenFlag);

				return print;
			}

		};

		return print;
	}

	/**
	 * 
	 * @Description: 通力OL35
	 *
	 * @return
	 * @author zuohao(Harley)
	 * @date 2018年8月7日  
	 * @version: v1.0.0
	 */
	private SwingWorker<Void, Void> goPrintOL35() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL35 print = new OL35(printerSelector.getSelectedItem()
								.toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							// Constants.LABELLEFT900540E =
							// position.get(2).getLeft();
							// Constants.LABELTOP900540E =
							// position.get(2).getTop();
							// Constants.LABELLEFT900540 =
							// position.get(3).getLeft();
							// Constants.LABELTOP900540 =
							// position.get(3).getTop();
							Constants.LABELLEFT80420 = position.get(5)
									.getLeft();
							Constants.LABELTOP80420 = position.get(5).getTop();
							System.out.println("LABELTOP80420:"
									+ position.get(5).getTop() + "size:"
									+ position.size());

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F310", subSerianNo);
							print.setSerialNo(serialNo);
							
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getTypeNo1(),"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");// 生成二维码图片(内容为TypeNo1)
//							c.printDimensionalCode(print.getSerialNo(),"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");// 生成一维码图片
//							c.printDimensionalCode(print.getTypeNo(),"C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");// 生成一维码图片
							print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}
			

			private OL35 generateOtherInfo(OL35 print, PrintInModel p) {
				// TODO Auto-generated method stub
				// item=7T3AMG25R6HM09A
				/** 物料号 */
				String item = p.getItemCode().trim();
				/** 物料号五位之后 */
				String item1 = null;
				/** 物料号G17 */
				String item2 = null;
				/** 左右 */
				String item3 = null;
				/** 提拉力 */
				String item4 = null;
				String carCwt = null;
				if (item.contains("X35")) {
					print.setModelNo("80420");
					print.setElevatorNo("OL35");
					// lenFlag = p.getLabelType().substring(0, 1);
					String type = item.substring(4, 5);
					item1 = item.substring(6, 9);// G23
					String item6 = item.substring(5, 6);// 中英文判断
					item2 = item.substring(6, 9);
					item3 = item.substring(9, 10);// L|R
					item4 = item.substring(5, 6);// 标准(样式)
					item.substring(9, 10);
					carCwt = item.substring(4,5);
					
					/** CAR */
					String technicalParameters = "CAR";
					if (item1.equals("G91")) {
						if (type.equals("C")) {//--
							print.setVns("1.50");
							print.setVcs("1.73");
							print.setVts("1.88");
						}
						if (type.equals("D")) {//--
							print.setVns("1.50");
							print.setVcs("1.90");
							print.setVts("2.06");
						}
						if (type.equals("E")) {//--
							print.setVns("1.75");
							print.setVcs("2.01");
							print.setVts("2.19");
						}
						if (type.equals("F")) {
							print.setVns("1.75");
							print.setVcs("2.01");//2.01
							print.setVts("2.19");
							technicalParameters = "CWT";
						}
					} else if (item1.equals("G92")) {
						if (type.equals("C")) {//--
							print.setVns("1.50");
							print.setVcs("1.73");
							print.setVts("1.88");
						}
						if (type.equals("D")) {//--
							print.setVns("1.50");
							print.setVcs("1.90");
							print.setVts("2.06");
						}
						if (type.equals("E")) {
							print.setVns("1.75");
							print.setVcs("2.01");//1.73
							print.setVts("2.19");
						}
						if (type.equals("F")) {
							print.setVns("1.75");
							print.setVcs("2.21");//2.01
							print.setVts("2.41");
						}
					}

					else {
						// 规则匹配
						File file = new File(Constants.RULEPATH);
						try {

							List<RuleInfo> list = ExcelPrintRule
									.readExcel(file);
							for (int i = 0; i < list.size(); i++) {
								if (list.get(i).getType().equals(item2)
										&& list.get(i).getModelNo()
												.equals("80420")) {
									print.setVns(list.get(i).getVns());
									print.setVcs(list.get(i).getVcs());
									print.setVts(list.get(i).getVts());
									print.setTechnicalParameters(list.get(i)
											.getTechnicalParameters());
									System.out.println("technicalParameters:"+ list.get(i).getTechnicalParameters());
									if(carCwt.equals("A")){
										technicalParameters = "CAR";
									}else if(carCwt.equals("B")){
										technicalParameters = "CWT";
									}else{
										technicalParameters = list.get(i)
											.getTechnicalParameters();
									}
									
								} else {
									continue;
								}
							}
							// System.out.println("list.size():"+list.size());
							// System.out.println("file"+file);
						} catch (IOException e) {
							// TODO Auto-generated catch block
							JOptionPane.showMessageDialog(null, "規則匹配失敗！");
							e.printStackTrace();
						}
					}

					String typeNo = null;
					String typeNo1 = null;

					
					if(item6.equals("G")){
						String typeCN="";
						String typeLR="";
						//将car替换成轿厢，cwt替换成对重
						if(("ACEG").contains(type)){
							typeCN="-轿厢-";
						}else{
							typeCN="-对重-";
						}
						//将L替换成左，R替换成右
						if(item3.equals("L")){
							typeLR="左";
						}else{
							typeLR="右";
						}
						typeNo = "80420" + item1+typeCN + typeLR;// 编号
						System.out.println("type:"+typeNo);
						typeNo1 = "80420" + item1+typeCN+ typeLR;
					}else{
						typeNo = "80420" + item1 + "-" + technicalParameters + "-"
								+ item3;// 编号
						typeNo1 = "80420" + item1 + "-" + technicalParameters + "-"
								+ item3;
					}
					
					;// 二维码内容
					String fbrakeMin = null;
					fbrakeMin = "500";// 500N
					String lineThickness = "error";
					lineThickness = "6.0";

					String labelType = null;
					if (item4.equals("E")) {
						labelType = "EN81-1";
					} else if (item4.equals("G")) {
						labelType = "GB7588";
					} else if (item4.equals("U")) {
						labelType = "EN81-20";
					}

					print.setLineThickness(lineThickness);
					print.setFbrakeMin(fbrakeMin);
					print.setTypeNo(typeNo);
					print.setLabelType(labelType);
					print.setTypeNo1(typeNo1);
					print.setLenFlag(item4);
				} else if ((item.contains("Z515"))) {

				}
				return print;
			}

		};

		return print;
	}

	/**
	 * 子线程打印OL35附属证书标签。
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintOL35CN() {

		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL35CN print = new OL35CN(printerSelector
								.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTOL35CNE = position.get(5)
									.getLeft();
							Constants.LABELTOPOL35CNE = position.get(5)
									.getTop();

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F310", subSerianNo);
							print.setSerialNo(serialNo);
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getTypeNo(),
									"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");// 生成二维码图片
							c.printDimensionalCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");// 生成一维码图片
							c.printDimensionalCode(print.getTypeNo(),
									"C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");// 生成一维码图片
							print.setLabelType(p.getLabelType());
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private OL35CN generateOtherInfo(OL35CN print, PrintInModel p) {
				// TODO Auto-generated method stub
				// item=7T3AMG25R6HM09A
				String item = p.getItemCode().trim();
				/** 语言 */
				String lenFlag = null;
				/** 物料号五位之后 */
				String item1 = null;
				/** 物料号G17 */
				String item2 = null;
				/** 左右 */
				String item3 = null;
				/** 提拉力 */
				String item4 = null;
				/** 鋼絲繩直徑 */
				String item5 = null;
				if (item.contains("7T3A")) {
					String typeflag = null;
					print.setModelNo("900540");
					if (item.substring(4, 5).equals("M")
							|| item.substring(4, 5).equals("E")) {
						typeflag = item.substring(4, 5);

					} else {
						typeflag = "";
					}
					print.setElevatorNo("OL35" + typeflag);
					lenFlag = p.getLabelType().substring(0, 1);
					item1 = item.substring(5);
					item2 = item.substring(5, 8);
					item3 = item.substring(8, 9);
					item4 = item.substring(4, 5);
					item5 = item.substring(9, 10);
					
					/** CAR */
					String technicalParameters = null;

					File file = new File(Constants.RULEPATH);
					try {

						List<RuleInfo> list = ExcelPrintRule.readExcel(file);
						for (int i = 0; i < list.size(); i++) {
							if (list.get(i).getType().equals(item2)
									&& list.get(i).getModelNo()
											.equals("900540")) {
								print.setVns(list.get(i).getVns());
								print.setVcs(list.get(i).getVcs());
								print.setVts(list.get(i).getVts());
								technicalParameters = list.get(i)
										.getTechnicalParameters();
							} else {
								continue;
							}

						}
					} catch (IOException e) {
						// TODO Auto-generated catch block
						JOptionPane.showMessageDialog(null, "規則匹配失敗！");
						e.printStackTrace();
					}

					String typeNo = null;
					if (lenFlag.equals("E")) {
						typeNo = "900540" + item1 + "-" + technicalParameters
								+ "-" + item3;
					} else {
						typeNo = "900540" + item1;
					}
					String fbrakeMin = null;
					if (item4.equals("M")) {
						fbrakeMin = "1100";
					} else if (item4.equals("O")) {
						fbrakeMin = "500";
					} else if (item4.equals("E")) {
						fbrakeMin = "800";
					}
					String lineThickness = "error";
					if (item5.equals("1")) {
						lineThickness = "10.0";
					} else if (item5.equals("8")) {
						lineThickness = "8.0";
					} else if (item5.equals("6")) {
						lineThickness = "6.0";
					}
					file = new File(Constants.CERTIFICATEPATH);
					try {
						List<CertificateInfo> list = ExcelCertificateNo
								.readExcel(file);
						for (int i = 0; i < list.size(); i++) {

							if ((lenFlag.equals("G")
									&& list.get(i).getModelNo()
											.equals(print.getElevatorNo())
									&& list.get(i).getLineThickness()
											.equals(lineThickness) && list
									.get(i).getVns().equals(print.getVns()))
									|| (lenFlag.equals("E") && list
											.get(i)
											.getModelNo()
											.equals(print.getElevatorNo() + "E"))) {
								try {
									Date expDate = sdf.parse(list.get(i)
											.getExpireDate());
									Date date = new Date();
									if (expDate.getTime() <= date.getTime()) {
										JOptionPane.showMessageDialog(null,
												"证书已过期！");
										return null;
									} else {
										print.setCertificateNo(list.get(i)
												.getCertificateNo());
										print.setTestingAgency(list.get(i)
												.getTestingAgency());
									}
								} catch (ParseException e) {
									// TODO Auto-generated catch block
									JOptionPane.showMessageDialog(null,
											"证书匹配失敗！");
									e.printStackTrace();
								}
							} else {
								continue;
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
					print.setLineThickness(lineThickness);
					print.setFbrakeMin(fbrakeMin);
					System.out.println("typeNo:"+typeNo);
					print.setTypeNo(typeNo);
					print.setLenFlag(lenFlag);
				} else if ((item.contains("Z515"))) {

				}
				return print;
			}

		};

		return print;
	}

	/**
	 * 子线程打印OL25标签。 1018300
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintOL25() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL25 print = new OL25(printerSelector.getSelectedItem()
								.toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFT1018300E = position.get(6)
									.getLeft();
							Constants.LABELTOP1018300E = position.get(6)
									.getTop();
							Constants.LABELLEFT1018300 = position.get(7)
									.getLeft();
							Constants.LABELTOP1018300 = position.get(7)
									.getTop();

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F310", subSerianNo);
							print.setSerialNo(serialNo);
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getTypeNo(),
									"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");// 生成二维码图片

							c.printDimensionalCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");// 生成一维码图片

							c.printDimensionalCode(print.getTypeNo(),
									"C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");// 生成一维码图片
							print.setLabelType(p.getLabelType());
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private OL25 generateOtherInfo(OL25 print, PrintInModel p) {
				// TODO Auto-generated method stub
				// item=1020934A01
				String item = p.getItemCode().trim();
				/** 语言 */
				String lenFlag = "G";
				/** 物料号G17 */
				String item2 = null;
				if (item.substring(0, 2).equals("CE")) {
					lenFlag = "E";
				}
				print.setModelNo("1018300");
				print.setElevatorNo("OL25");
				item2 = item.substring(7, 10);
				// item5=item.substring(9,10);
				/** CAR */
				// String technicalParameters=null;

				File file = new File(Constants.RULEPATH);
				try {

					List<RuleInfo> list = ExcelPrintRule.readExcel(file);
					for (int i = 0; i < list.size(); i++) {
						if (list.get(i).getType().equals(item2)
								&& list.get(i).getModelNo().equals("1018300")) {
							print.setVns(list.get(i).getVns());

							if (list.get(i).getVcs().contains("1.14999")) {
								list.get(i).setVcs("1.15");
							}
							print.setVcs(list.get(i).getVcs());
							print.setVts(list.get(i).getVts());
						} else {
							continue;
						}

					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "規則匹配失敗！");
					e.printStackTrace();
				}

				String typeNo = null;
				if (lenFlag.equals("E")) {
					typeNo = "1018300" + item2;
				} else {
					typeNo = "1018300" + item2;
				}
				p.getItemDesc().trim();

				String lineThickness = "error";
				int item22 = Integer.parseInt(item2.substring(1, 3));
				if ((0 < item22 && item22 < 41) || (item22 > 80 && item22 < 85)
						|| (item22 > 90 && item22 < 95)) {
					lineThickness = "8.0";
				} else if ((40 < item22 && item22 < 81)
						|| (item22 > 84 && item22 < 89)
						|| (item22 > 94 && item22 < 99)) {
					lineThickness = "6.0";
				}

				file = new File(Constants.CERTIFICATEPATH);
				try {
					List<CertificateInfo> list = ExcelCertificateNo
							.readExcel(file);
					for (int i = 0; i < list.size(); i++) {

						if ((lenFlag.equals("G")
								&& list.get(i).getModelNo().equals("OL25")
								&& list.get(i).getLineThickness()
										.equals(lineThickness) && list.get(i)
								.getVns().equals(print.getVns()))
								|| (lenFlag.equals("E") && list.get(i)
										.getModelNo().equals("OL25E"))) {
							try {
								Date expDate = sdf.parse(list.get(i)
										.getExpireDate());
								Date date = new Date();
								if (expDate.getTime() <= date.getTime()) {
									JOptionPane.showMessageDialog(null,
											"证书已过期！");
									return null;
								} else {
									print.setCertificateNo(list.get(i)
											.getCertificateNo());
									print.setTestingAgency(list.get(i)
											.getTestingAgency());
								}
							} catch (ParseException e) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null, "证书匹配失敗！");
								e.printStackTrace();
							}
						} else {
							continue;
						}
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
				print.setLineThickness(lineThickness);
				print.setTypeNo(typeNo);
				print.setLenFlag(lenFlag);

				return print;
			}

		};

		return print;
	}

	/**
	 * 子线程打印迅达SGB标签。
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintSGB() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						SGB02 print = new SGB02(printerSelector
								.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTSGB = position.get(8).getLeft();
							Constants.LABELTOPSGB = position.get(8).getTop();
							System.out.println("LABELTOPSGB:"
									+ position.get(8).getTop() + "left:"
									+ position.get(8).getLeft());
						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F320", subSerianNo);
							print.setSerialNo(serialNo);
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							// c.printQRCode(print.getTypeNo1(),
							// "C:/toolsZ/labelPrint/codeZ/typeNo.jpg");//
							// 生成二维码图片(内容为TypeNo1)
							c.printDimensionalCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");// 生成一维码图片
							// c.printDimensionalCode(print.getTypeNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							// print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private SGB02 generateOtherInfo(SGB02 print, PrintInModel p) {

				/**
				 * elevatorNO物料描述,物料类别
				 */

				String elevatorNO = p.getItemDesc().replace(" ", "")
						.substring(0, 5);

				String item1 = p.getItemDesc().replace(" ", "");// 物料类别
				/**
				 * 实际交货日_10
				 */
				String deliveryDate = p.getOther().trim();

				/**
				 * 客户合同号
				 */
				String agreementNum = p.getLabelType().replace(" ", "");

				String fkg = null;

				String flb = null;

				String fMax = null;

				String fmlb = null;

				String vMax = null;

				String vmfpm = null;

				String vkn = null;

				String vkfpm = null;

				String k = null;

				String typeNo = null;

				String typeNo1 = null;

				typeNo = elevatorNO + "-" + "904373G"
						+ deliveryDate.substring(8, 10);// 最上面的数字
				typeNo1 = typeNo;// 二维码内容

				vkn = agreementNum.substring(agreementNum.indexOf("VKN="),
						agreementNum.indexOf("VMAX")).substring(4);
				if (agreementNum.contains("润滑")) {
					guideRail = "润滑";
					setGuideRail(guideRail);
//					fkg = "1780-3060";
//					flb = "3924-6746";
					vMax = agreementNum.substring(
							agreementNum.indexOf("VMAX="),
							agreementNum.indexOf("润滑导轨")).substring(5);
					FRange fRange = new SGBFRangeSet().getLubricationF(elevatorNO, vkn);
					fkg = fRange.getFkg();
					flb = fRange.getFlb();

				} else if (agreementNum.contains("干燥")) {
					guideRail = "干燥";
					setGuideRail(guideRail);
//					fkg = "1350-3600";
//					flb = "2976-7936";
					vMax = agreementNum.substring(
							agreementNum.indexOf("VMAX="),
							agreementNum.indexOf("干燥导轨")).substring(5);
					FRange fRange = new SGBFRangeSet().getDryF(elevatorNO, vkn);
					fkg = fRange.getFkg();
					flb = fRange.getFlb();

				}
				// GGU=1667,VKN=1 VMAX=1.65润滑导轨丶机加工导轨 安装国家：中国 EN81-20/50=N
				fMax = agreementNum.substring(agreementNum.indexOf("GGU="),
						agreementNum.indexOf(",VKN")).substring(4);
				double fmx = Double.parseDouble(fMax);
				fmlb = String.valueOf(Math.round(Long.valueOf(fMax) * 2.20462));

				vmfpm = String
						.valueOf(Math.round(Double.valueOf(vMax) * 196.85039));

				vkn = agreementNum.substring(agreementNum.indexOf("VKN="),
						agreementNum.indexOf("VMAX")).substring(4);
				vkn = String.format("%.2f", Double.parseDouble(vkn));
				vkfpm = String
						.valueOf(Math.round(Double.valueOf(vkn) * 196.85039));

				k = item1.substring(item1.indexOf("安全钳"), item1.indexOf("mm"))
						.substring(3);
				if (k.contains("9/10")) {
					k = "10";
				}
				System.out.println(getGuideRail());
				String A = "";
				File file = new File(Constants.SGBRULEPATH);
				try {
					List<SgbRuleInfo> list = ExcelSgbPrintRule.readExcel(file);
					int j = 0;
					int l = 0;

					String itemT;
					String itemA;
					String itemB;
					String x = "";

					for (int i = 0; i < list.size(); i++) {
						if (guideRail.equals("润滑")
								&& list.get(i).getTypeO().equals("oiled")) {
							if (elevatorNO.equals("SGB05")) {
								if (Double.parseDouble(vkn) <= 1.5) {
									itemT = list.get(i).getSgbO5V15();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else {
									itemT = list.get(i).getSgbO5V25();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								}
							} else if (elevatorNO.equals("SGB01")) {
								itemT = list.get(i).getSgbO1V25();
								if (!itemT.equals("*")) {
									itemA = itemT.substring(0,
											itemT.indexOf("-"));
									itemB = itemT
											.substring(itemT.indexOf("-") + 1);
									if (fmx >= Double.parseDouble(itemA)
											&& fmx <= Double.parseDouble(itemB)) {
										x = list.get(i).getX();
									}
								}
							} else if (elevatorNO.equals("SGB02")) {
								itemT = list.get(i).getSgbO2V25();
								if (!itemT.equals("*")) {
									itemA = itemT.substring(0,
											itemT.indexOf("-"));
									itemB = itemT
											.substring(itemT.indexOf("-") + 1);
									if (fmx >= Double.parseDouble(itemA)
											&& fmx <= Double.parseDouble(itemB)) {
										x = list.get(i).getX();
									}
								}
							} else if (elevatorNO.equals("SGB03")) {
								itemT = list.get(i).getSgbO3V25();
								if (!itemT.equals("*")) {
									itemA = itemT.substring(0,
											itemT.indexOf("-"));
									itemB = itemT
											.substring(itemT.indexOf("-") + 1);
									if (fmx >= Double.parseDouble(itemA)
											&& fmx <= Double.parseDouble(itemB)) {
										x = list.get(i).getX();
									}
								}
							}
						} else if (guideRail.equals("干燥")
								&& list.get(i).getTypeO().equals("dry")) {
							if (elevatorNO.equals("SGB05")) {
								itemT = list.get(i).getSgbD5V25();
								if (!itemT.equals("*")) {
									itemA = itemT.substring(0,
											itemT.indexOf("-"));
									itemB = itemT
											.substring(itemT.indexOf("-") + 1);
									if (fmx >= Double.parseDouble(itemA)
											&& fmx <= Double.parseDouble(itemB)) {
										x = list.get(i).getX();
									}
								}
							} else if (elevatorNO.equals("SGB01")) {
								if (Double.parseDouble(vkn) <= 2.5) {
									itemT = list.get(i).getSgbD1V25();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else if (Double.parseDouble(vkn) <= 3
										&& Double.parseDouble(vkn) > 2.5) {
									itemT = list.get(i).getSgbD1V30();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else if (Double.parseDouble(vkn) <= 3.5
										&& Double.parseDouble(vkn) > 3) {
									itemT = list.get(i).getSgbD1V35();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								}
							} else if (elevatorNO.equals("SGB02")) {
								if (Double.parseDouble(vkn) <= 1.5) {
									itemT = list.get(i).getSgbD2V15();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else if (Double.parseDouble(vkn) <= 2.5
										&& Double.parseDouble(vkn) > 1.5) {
									itemT = list.get(i).getSgbD2V25();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else if (Double.parseDouble(vkn) <= 3.5
										&& Double.parseDouble(vkn) > 2.5) {
									itemT = list.get(i).getSgbD2V35();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								}

							} else if (elevatorNO.equals("SGB03")) {
								if (Double.parseDouble(vkn) <= 2.5) {
									itemT = list.get(i).getSgbD3V25();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								} else if (Double.parseDouble(vkn) <= 3.5
										&& Double.parseDouble(vkn) > 12.5) {
									itemT = list.get(i).getSgbD3V35();
									if (!itemT.equals("*")) {
										itemA = itemT.substring(0,
												itemT.indexOf("-"));
										itemB = itemT.substring(itemT
												.indexOf("-") + 1);
										if (fmx >= Double.parseDouble(itemA)
												&& fmx <= Double
														.parseDouble(itemB)) {
											x = list.get(i).getX();
										}
									}
								}
							}
						}
						if (list.get(i).getTypeO().equals("A")
								&& !list.get(i).getX().equals("*")) {
							if (Double.parseDouble(k) == 8
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk8();
							} else if (Double.parseDouble(k) == 9
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk9();
							} else if (Double.parseDouble(k) == 10
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk10();
							} else if (Double.parseDouble(k) == 12
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk12();
							} else if (Double.parseDouble(k) == 14
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk14();
							} else if (Double.parseDouble(k) == 15.88
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk15();
							} else if (Double.parseDouble(k) == 16
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk16();
							} else if (Double.parseDouble(k) == 19
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk19();
							} else if (Double.parseDouble(k) == 28.6
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk28();
							} else if (Double.parseDouble(k) == 31.75
									&& list.get(i).getX().equals(x)) {
								A = list.get(i).getSgbAk31();
							}

						}

						// if (list.get(i).getType().equals("SGB01")) {
						// System.out.println("sgb01");
						// } else {
						// continue;
						// }
					}
					System.out.println("oiled:" + j + "dry" + l + "zongsh"
							+ list.size());
					// System.out.println("list.size():"+list.size());
					// System.out.println("file"+file);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					JOptionPane.showMessageDialog(null, "規則匹配失敗！");
					e.printStackTrace();
				}

				print.setTypeNo(typeNo);// 主编码
				print.setTypeNo1(typeNo1);// 二维码
				print.setElevatorNo(elevatorNO);

				print.setF(fkg);
				print.setFlb(flb);
				print.setFmax(fMax);
				print.setFmlb(fmlb);

				print.setVmax(vMax);
				print.setVmfpm(vmfpm);
				print.setVkn(vkn);
				print.setVkfpm(vkfpm);
				print.setK(k);
				print.setGuidrail(guideRail);

				DecimalFormat df = new DecimalFormat(".0");// 保留两位小数
				print.setA(df.format(Double.parseDouble(A)));
				// ;

				// }
				return print;
			}

		};

		return print;
	}

	/**
	 * 子线程打印SGB05标签。
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintSGB05() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						SGB05 print = new SGB05(printerSelector
								.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTSGB05 = position.get(9)
									.getLeft();
							Constants.LABELTOPSGB05 = position.get(9).getTop();
							System.out.println("LABELTOPSGB05:"
									+ position.get(9).getTop() + "left:"
									+ position.get(9).getLeft());
						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F320", subSerianNo);
							print.setSerialNo(serialNo);
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getElevatorNo(),
									"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");//
							// 生成二维码图片(内容为TypeNo1)
							// c.printDimensionalCode(print.getElevatorNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							// c.printDimensionalCode(print.getTypeNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							// print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private SGB05 generateOtherInfo(SGB05 print, PrintInModel P) {

				/**
				 * elevatorNO物料描述,物料类别
				 */
				String elevatorNO = P.getElevator().replace(" ", "");
				// String item1 = p.getItemDesc().replace(" ", "");// 物料类别
//				String fkg = "1850-3600";
//				String flb = "4078-7936";
				String fkg = null;
				String flb = null;
				if(P.getItemCode().contains("A11")||P.getItemCode().contains("A12")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB01", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB01", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
					
				} else if(P.getItemCode().contains("A21")||P.getItemCode().contains("A22")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB02", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB02", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
				} else if(P.getItemCode().contains("A51")||P.getItemCode().contains("A52")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB05", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB05", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
				}
				

				String fMax = P.getfMax().replace(" ", "");

				String fmlb = "";

				Double.parseDouble(fMax);

				fmlb = String
						.valueOf(Math.round(Double.valueOf(fMax) * 2.20462));

				String vMax = P.getvMax();

				String vmfpm = "";

				vmfpm = String
						.valueOf(Math.round(Double.valueOf(vMax) * 196.85039));

				String typeNo = null;

				String typeNo1 = null;

				typeNo = P.getLabelType().trim() + "-"
						+ P.getOther().substring(0, 9);// 最上面的数字

				typeNo1 = typeNo;// 二维码内容

				String A = P.getA();

				print.setTypeNo(typeNo);// 主编码
				print.setTypeNo1(typeNo1);// 二维码
				print.setElevatorNo(elevatorNO);

				print.setF(fkg);
				print.setFlb(flb);
				print.setFmax(fMax);
				print.setFmlb(fmlb);

				print.setVmax(vMax);
				print.setVmfpm(vmfpm);

				DecimalFormat df = new DecimalFormat(".00");// 保留两位小数
				print.setA(df.format(Double.parseDouble(A)));

				return print;
			}

		};

		return print;
	}

	/**
	 * 子线程打印SGB05CN标签。 中文标签
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintSGB05CN() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						SGB05CN print = new SGB05CN(printerSelector
								.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTSGB05CN = position.get(10)
									.getLeft();
							Constants.LABELTOPSGB05CN = position.get(10)
									.getTop();
							System.out.println("LABELTOPSGB05CN:"
									+ position.get(10).getTop() + "left:"
									+ position.get(10).getLeft());
						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F320", subSerianNo);
							print.setSerialNo(serialNo);
							
							CodeAndPrint c = new CodeAndPrint();
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							c.printQRCode(print.getElevatorNo(),
									"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");//
							// 生成二维码图片(内容为TypeNo1)
							// c.printDimensionalCode(print.getElevatorNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							// c.printDimensionalCode(print.getTypeNo(),
							// "C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							// print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private SGB05CN generateOtherInfo(SGB05CN print, PrintInModel P) {

				/**
				 * elevatorNO物料描述,物料类别
				 */
				String elevatorNO = P.getElevator().replace(" ", "");
				// String item1 = p.getItemDesc().replace(" ", "");// 物料类别

//				String fkg = "1850-3600";
//				String flb = "4078-7936";
				String fkg = null;
				String flb = null;
				if(P.getItemCode().contains("A11")||P.getItemCode().contains("A12")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB01", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB01", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
					
				} else if(P.getItemCode().contains("A21")||P.getItemCode().contains("A22")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB02", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB02", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
				} else if(P.getItemCode().contains("A51")||P.getItemCode().contains("A52")){
					if(P.getItemCode().contains("D")){
						FRange frange = new SGBFRangeSet().getDryFKone("SGB05", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}else{
						FRange frange = new SGBFRangeSet().getLubricationFKone("SGB05", P.getvMax());
						fkg = frange.getFkg();
						flb = frange.getFlb();
					}
				}

				String fMax = P.getfMax().replace(" ", "");

				// String fmlb ="";
				//
				// double fmx = Double.parseDouble(fMax);
				//
				// fmlb = String.valueOf(Math.round(Double.valueOf(fMax) *
				// 2.20462));

				String vMax = P.getvMax();

				// String vmfpm = "";
				//
				// vmfpm = String.valueOf(Math.round(Double.valueOf(vMax) *
				// 196.85039));
				String d = "";
				String l = "";
				String dlStatus = P.getItemCode().trim().substring(11, 12);
				if (dlStatus.equals("D")) {
					d = "√";
				} else {
					l = "√";
				}

				String typeNo = null;

				String type = null;

				typeNo = P.getLabelType().trim() + "-"
						+ P.getOther().substring(0, 8);// MainNO

				type = P.getLabelType().trim();// 型号

				String A = P.getA();
				DecimalFormat dg = new DecimalFormat(".00");// 保留两位小数

				print.setTypeNo(typeNo);// 主编码
				print.setTypeNo1(type);// 型号
				print.setElevatorNo(elevatorNO);// elevatorNO
				print.setF(fkg);
				print.setFlb(flb);
				print.setFmax(fMax);
				print.setVmax(dg.format(Double.parseDouble(vMax)));
				// print.setVmax(vMax);
				print.setD(d);
				print.setL(l);

				DecimalFormat df = new DecimalFormat(".0");// 保留两位小数
				print.setA(df.format(Double.parseDouble(A)));

				return print;
			}

		};

		return print;
	}

	/**
	 * OL35SCHINDLERCN中文打印 迅达中文标签
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintOL35SCHINDLERCN() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL35SCHINDLERCN print = new OL35SCHINDLERCN(
								printerSelector.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTOL35SCHINDLERCN = position.get(
									12).getLeft();
							Constants.LABELTOPOL35SCHINDLERCN = position
									.get(12).getTop();
							System.out.println("LABELLEFTOL35SCHINDLERCN:"
									+ position.get(12).getTop() + "size:"
									+ position.size());

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
								String originSerianNo= p.getSerialNo();
								String subSerianNo=originSerianNo.substring(2,10);
								String serialNo =CodeGenerate.getCode("F310", subSerianNo);
								print.setSerialNo(serialNo);
							
							CodeAndPrint c = new CodeAndPrint();
							 c.printQRCode(print.getSerialNo(),"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");//
							// 生成二维码图片
							 c.printQRCode(print.getTypeNo(),"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");//
							// 生成二维码图片(内容为TypeNo1)
//							c.printDimensionalCode(print.getSerialNo(),
//									"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");// 生成一维码图片
							System.out.println("-------" + print.getSerialNo());
							// c.printDimensionalCode(print.getTypeNo(),"C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private OL35SCHINDLERCN generateOtherInfo(OL35SCHINDLERCN print,
					PrintInModel p) {
				// TODO Auto-generated method stub
				// item=7T3AMG25R6HM09A
				/** 物料号 */
				String item = p.getItemCode().trim();
				/** 型号 */
				// String type = "OL35" + item.substring(4, 5);
				String mainG = item.substring(7, 10);// 物料号Gxx
				System.out.println("物料号："+mainG);
				String minLR = item.substring(10, 11);// 物料号第11位,L:left OR
														// R:right
				String usage = item.substring(5, 6);// 物料号第6位ABCDEF ACE=>CAR
				System.out.println("输出是不是轿厢或对重测"+usage);							// BDF=>CWT
				String mainEnd = item.substring(11);// 物料号11位以后
				//若果是CAR则替换"-轿厢-"中文字符，反之替换为"-对重-"
				if (("ACEGJL").contains(usage)) {
					usage = "-轿厢-";
				} else {
					usage = "-对重-";
				}
				//为L则替换成中文"左"，反之替成"右"
				if(minLR.equals("L")){
					minLR="左";
				}else{
					minLR="右";
				}
				/** mainCode */
//				String mainCode = "900540" + mainG + minLR + mainEnd + "-"
//						+ usage + "-" + minLR;
				String mainCode = "900540" + mainG + usage + minLR;
				//重新获取物料号Gxx，用于判断是不是G91的产品
				usage=item.substring(5, 6);
				/** 张紧力 */
				String fensionForce = null;
				/** 提拉力 */
				String pullForce = null;
				/** 类型 */
				String mainType = item.substring(4, 5);
				System.out.println("输出类型："+mainType);
				if (mainType.equals("O")) {
					mainType = "OL35";
					fensionForce = "125";
					pullForce = "500";
				} else if (mainType.equals("E")) {
					mainType = "OL35";
					fensionForce = "300";
					pullForce = "800";
				} else if (mainType.equals("M")) {
					mainType = "OL35M";
					fensionForce = "300";
					pullForce = "1100";
				}else if(mainType.equals("F")){
					mainType = "OL35F";
					fensionForce = "125";
					pullForce = "500";
				} else {
					mainType = "OL35M";
					fensionForce = "300";
					pullForce = "500";
				}
				/** 鋼絲繩直徑 */
				double diameter;
				diameter = Integer.parseInt(mainG.substring(1));
				if (diameter <= 30||diameter==91) {
					diameter = 6.0;
				} else {
					diameter = 8.0;
				}
				System.out.println("输出物料号是不是G91"+item);
				if (item.contains("7T")) {
					File file = new File(Constants.RULEPATH);
					if (mainG.equals("G91")) {
						if (usage.equals("C")) {
							print.setVns("1.50");
							print.setVcs("1.73");
							print.setVts("1.88");
						}
						if (usage.equals("D")) {
							print.setVns("1.50");
							print.setVcs("1.90");
							print.setVts("2.06");
						}
						if (usage.equals("E")) {
							print.setVns("1.75");
							print.setVcs("2.01");
							print.setVts("2.19");
						}
						if (usage.equals("F")) {
							print.setVns("1.75");
							print.setVcs("2.21");
							print.setVts("2.41");
//							print.setVns("1.75");
//							print.setVcs("2.01");//2.01
//							print.setVts("2.19");
						}
						 if (usage.equals("G")) {
				              print.setVns("1.75");
				              print.setVcs("2.05");
				              print.setVts("2.19");
				            }
				            if (usage.equals("H")) {
				              print.setVns("1.75");
				              print.setVcs("2.26");
				              print.setVts("2.41");
				            }
				            System.out.println("进来了"+usage+""+usage.equals("J"));
				            if (usage.equals("J")) {
				              print.setVns("2.50");
				              print.setVcs("2.88");
				              print.setVts("3.05");
				            }
				            if (usage.equals("K")) {
				              print.setVns("2.50");
				              print.setVcs("3.16");
				              print.setVts("3.22");
				            }
				            if (usage.equals("L")) {
				              print.setVns("3.00");
				              print.setVcs("3.45");
				              print.setVts("3.69");
				            }
				            if (usage.equals("M")) {
				              print.setVns("3.00");
				              print.setVcs("3.80");
				              print.setVts("4.06");
				            }
					} else if (mainG.equals("G92")) {
						if (usage.equals("C")) {
							print.setVns("1.50");
							print.setVcs("1.73");
							print.setVts("1.88");
						}
						if (usage.equals("D")) {
							print.setVns("1.50");
							print.setVcs("1.90");
							print.setVts("2.06");
						}
						if (usage.equals("E")) {
							print.setVns("1.75");
							print.setVcs("2.01");
							print.setVts("2.19");
						}
						if (usage.equals("F")) {
							print.setVns("1.75");
							print.setVcs("2.21");
							print.setVts("2.41");
						}
					}else{
						// 规则匹配
						try {

							List<RuleInfo> list = ExcelPrintRule.readExcel(file);
							for (int i = 0; i < list.size(); i++) {
								if (list.get(i).getType().equals(mainG)
										&& list.get(i).getModelNo()
												.equals("900540")) {
									print.setVns(list.get(i).getVns());
									print.setVcs(list.get(i).getVcs());
									print.setVts(list.get(i).getVts());
								} else {
									continue;
								}
							}
						} catch (IOException e) {
							JOptionPane.showMessageDialog(null, "規則匹配失敗！");
							e.printStackTrace();
						}
					}
					
					
					
					
					file = new File(Constants.CERTIFICATEPATH);
					try {
						List<CertificateInfo> list = ExcelCertificateNo.readExcel(file);
						for (int i = 0; i < list.size(); i++) {
							// 如果mainType = "OL35M";并且diameter钢丝直径
							// System.out.println("i:" +i +";ModelNo:" +
							// list.get(i).getModelNo() +";LineThickness:"+
							// list.get(i).getLineThickness() +";Vns:"+
							// list.get(i).getVns() + ";print.vns:" +
							// print.getVns());
							if ((list.get(i).getModelNo().equals(mainType)
									&& list.get(i).getLineThickness().equals(String.valueOf(diameter)) && list.get(i).getVns().equals(String.valueOf(print.getVns())))) {
								try {
									Date expDate = sdf.parse(list.get(i).getExpireDate());
									Date date = new Date();
									if (expDate.getTime() <= date.getTime()) {
										JOptionPane.showMessageDialog(null,"证书已过期！");
										print.setCertificateNo(list.get(i).getCertificateNo());
										print.setTestingAgency(list.get(i).getTestingAgency());
										// return null;
									} else {
										print.setCertificateNo(list.get(i).getCertificateNo());
										print.setTestingAgency(list.get(i).getTestingAgency());
									}
								} catch (ParseException e) {
									// TODO Auto-generated catch block
									JOptionPane.showMessageDialog(null,
											"证书匹配失敗！");
									e.printStackTrace();
								}
							} else {
								continue;
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
					
					print.setTypeNo(mainCode);
					if(mainType=="OL35F"){
						mainType="OL35M";
					}
					print.setMainType(mainType);
					print.setPullForce(pullForce);
					print.setDiameter(diameter);
					print.setFensionForce(fensionForce);
					// String typeNo1 = null;
					// print.setElevatorNo("OL35");
					// print.setSerialNo(serialNo);
					// print.setFbrakeMin();
					// print.setTypeNo1(typeNo1);
					// print.setLenFlag();
				}
				return print;
			}

		};

		return print;
	}

	/**
	 * OL35SCHINDLER英文打印 迅达中文标签
	 * 
	 * @return
	 */
	private SwingWorker<Void, Void> goPrintOL35SCHINDLER() {
		SwingWorker<Void, Void> print = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() {
				try {
					List<PrintInModel> selectedList = new ArrayList<PrintInModel>();
					for (int i : selectedRow) {
						selectedList.add(list.get(i));
					}
					// System.out.println(list);
					if (selectedList.size() > 0) {
						// 实例化打印机对象
						OL35SCHINDLER print = new OL35SCHINDLER(printerSelector.getSelectedItem().toString());

						// 设置边距
						SqliteDao sd = new SqliteDao();
						try {
							List<Adjustment> position = sd.getPosition();
							Constants.LABELLEFTOL35SCHINDLER = position.get(11)
									.getLeft();
							Constants.LABELTOPOL35SCHINDLER = position.get(11)
									.getTop();
							System.out.println("OL35SCHINDLER设置边距上边距:"
									+ position.get(11).getTop() + ";左边距:"
									+ position.get(11).getLeft());

						} catch (Exception e) {
							e.printStackTrace();
							JOptionPane.showMessageDialog(null, "设置边距出现问题：\n"
									+ e.getMessage());
						}
						for (PrintInModel p : selectedList) {
							print = generateOtherInfo(print, p);
							String newDate = sdf.format(sdf.parse(textNewDate
									.getText().toString()));
							print.setProdDatea(newDate);
							//设置追溯码
							String originSerianNo= p.getSerialNo();
							String subSerianNo=originSerianNo.substring(2,10);
							String serialNo =CodeGenerate.getCode("F310", subSerianNo);
							print.setSerialNo(serialNo);
							CodeAndPrint c = new CodeAndPrint();
							
							if(print.getNorm().equals("EN81-20")){
								String traceability = print.getMainType()
										+ " --- --- "
										+ print.getTypeNo()
										+ " "
										+ print.getSerialNo()
										+ " --- WITTUR Elevator Components (Suzhou) CO., Ltd. 215214 Suzhou CN Wittur Holding GmbH 85259 Wiedenzhausen DE";
										c.printQRCode(traceability,
										"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");
							}else{
										String traceability = print.getMainType()
										+ " --- --- "
										+ print.getTypeNo()
										+ " "
										+ print.getSerialNo()
										+ " --- WITTUR Elevator Components (Suzhou) CO., Ltd. 215214 Suzhou CN --- --- --- ---";
										c.printQRCode(traceability,
										"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");
							}
							
							
							c.printQRCode(print.getSerialNo(),
									"C:/toolsZ/labelPrint/codeZ/serialNo.jpg");// 生成二维码图片
							// c.printQRCode(print.getTypeNo1(),"C:/toolsZ/labelPrint/codeZ/typeNo.jpg");//
							// 生成二维码图片(内容为TypeNo1)
							// c.printDimensionalCode(print.getSerialNo(),"C:/toolsZ/labelPrint/codeZ/DserialNo.jpg");//
							// 生成一维码图片
							// c.printDimensionalCode(print.getTypeNo(),"C:/toolsZ/labelPrint/codeZ/DtypeNo.jpg");//
							// 生成一维码图片
							print.setLabelType(p.getLabelType());
							// print.setLabelType(labelType);
							int num = Integer.parseInt(textNum.getText()
									.toString().trim());
							for (int i = 0; i < num; i++) {
								// 发送到打印机
								print.printcode();
								// 睡眠
								Thread.sleep(200);
							}

						}
					}
					return null;
				} catch (HeadlessException e) {
					e.printStackTrace();
				} catch (NullPointerException e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "数据信息不匹配！");
				} catch (Exception e) {
					e.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"ERROE : " + e.getMessage());
				} finally {
					// 设置为可以继续操作
					setEnableOperator();
					// 设置已经选择的行数
					selectedRow = null;
				}
				return null;
			}

			private OL35SCHINDLER generateOtherInfo(OL35SCHINDLER print,
					PrintInModel p) {
				// TODO Auto-generated method stub
				// item=7T3AMG25R6HM09A
				/** 物料号 */
				String item = p.getItemCode().trim();
				/** 型号 */
				// String type = "OL35" + item.substring(4, 5);

				String mainG = item.substring(7, 10);// 物料号Gxx
				System.out.println("mainG=="+mainG);
				String minLR = item.substring(10, 11);// 物料号第11位,L:left OR
														// R:right
				String usage = item.substring(5, 6);// 物料号第6位ABCDEF ACE=>CAR
													// BDF=>CWT
				String usage1 = null;

				/**
				 * X:EN81-1(全英文包装) Z:GB7588 U:EN81-20/50 Y: EN81-20/50(全英文包装)
				 * G:Schindler required(GB7588 & EN81-1)
				 */
				String norm = item.substring(6, 7);// 物料号第7位E:EN81-1
				if (norm.equals("X") || norm.equals("E")) {
					norm = "EN81";
				} else if (norm.equals("U") || norm.equals("Y")) {
					norm = "EN81-20";
				} else {
					JOptionPane.showMessageDialog(null,
							"未获取到对应Norm[NORM非指定X.E.U.Y]");
				}
				String mainEnd = item.substring(11);// 物料号11位以后
				if (usage.equals("A") || usage.equals("C") || usage.equals("E")||usage.equals("G")||usage.equals("J")||usage.equals("L")) {
					usage1 = "CAR";
				} else {
					usage1 = "CWT";
				}
				/** mainCode */
				String mainCode = "900540" + mainG + minLR + mainEnd + "-"
						+ usage1 + "-" + minLR;

				/** 张紧力 */
				String fensionForce = null;
				/** 提拉力 */
				String pullForce = null;
				/** 类型 */
				String mainType = item.substring(4, 5);
				if (mainType.equals("O")) {
					mainType = "OL35";
					fensionForce = "125";
					pullForce = "500";
				} else if (mainType.equals("E")) {
					mainType = "OL35E";
					fensionForce = "300";
					pullForce = "800";
				} else if (mainType.equals("M")) {
					mainType = "OL35M";
					fensionForce = "300";
					pullForce = "1100";
				} else if(mainType.equals("F")){
					mainType = "OL35F";
					fensionForce = "300";
					pullForce = "500";
				}else {
					mainType = "OL35M";
					fensionForce = "300";
					pullForce = "500";
				}
				/** 鋼絲繩直徑 */
				double diameter;
				diameter = Integer.parseInt(mainG.substring(1));
				if (diameter <= 30||diameter==91) {
					diameter = 6.0;
				} else {
					diameter = 8.0;
				}
				if (item.contains("7T")) {
					File file = new File(Constants.RULEPATH);

					if (mainG.equals("G91")) {
						if (usage.equals("C")) {
				              print.setVns("1.50");
				              print.setVcs("1.73");
				              print.setVts("1.88");
				            }
				            if (usage.equals("D")) {
				              print.setVns("1.50");
				              print.setVcs("1.90");
				              print.setVts("2.06");
				            }
				            if (usage.equals("E")) {
				              print.setVns("1.75");
				              print.setVcs("2.01");
				              print.setVts("2.19");
				            }
				            if (usage.equals("F")) {
				              print.setVns("1.75");
				              print.setVcs("2.21");
				              print.setVts("2.41");
				            }
				            if (usage.equals("G")) {
				              print.setVns("1.75");
				              print.setVcs("2.05");
				              print.setVts("2.19");
				            }
				            if (usage.equals("H")) {
				              print.setVns("1.75");
				              print.setVcs("2.26");
				              print.setVts("2.41");
				            }
				            if (usage.equals("J")) {
				              print.setVns("2.50");
				              print.setVcs("2.88");
				              print.setVts("3.05");
				            }
				            if (usage.equals("K")) {
				              print.setVns("2.50");
				              print.setVcs("3.16");
				              print.setVts("3.22");
				            }
				            if (usage.equals("L")) {
				              print.setVns("3.00");
				              print.setVcs("3.45");
				              print.setVts("3.69");
				            }
				            if (usage.equals("M")) {
				              print.setVns("3.00");
				              print.setVcs("3.80");
				              print.setVts("4.06");
				            }
					} else if (mainG.equals("G92")) {
						if (usage.equals("C")) {
							print.setVns("1.50");
							print.setVcs("1.73");
							print.setVts("1.88");
						}
						if (usage.equals("D")) {
							print.setVns("1.50");
							print.setVcs("1.90");
							print.setVts("2.06");
						}
						if (usage.equals("E")) {
							print.setVns("1.75");
							print.setVcs("2.01");
							print.setVts("2.19");
						}
						if (usage.equals("F")) {
							print.setVns("1.75");
							print.setVcs("2.21");
							print.setVts("2.41");
						}
					}else{
					// 规则匹配
					try {

						List<RuleInfo> list = ExcelPrintRule.readExcel(file);
						for (int i = 0; i < list.size(); i++) {
							if (list.get(i).getType().equals(mainG)
									&& list.get(i).getModelNo().equals("900540")) {
								DecimalFormat df = new DecimalFormat("#.00");
								print.setVns(list.get(i).getVns());
								print.setVcs(list.get(i).getVcs());
								print.setVts(list.get(i).getVts());
							} else {
								continue;
							}
						}
					} catch (IOException e) {
						JOptionPane.showMessageDialog(null, "規則匹配失敗！");
						e.printStackTrace();
					}
					}
					
					file = new File(Constants.CERTIFICATEPATH);
					try {
						List<CertificateInfo> list = ExcelCertificateNo
								.readExcel(file);
						for (int i = 0; i < list.size(); i++) {
							// 如果mainType = "OL35M";并且diameter钢丝直径
							// System.out.println("i:" +i +";ModelNo:" +
							// list.get(i).getModelNo() +";LineThickness:"+
							// list.get(i).getLineThickness() +";Vns:"+
							// list.get(i).getVns() + ";print.vns:" +
							// print.getVns());
							if ((list.get(i).getModelNo().equals(mainType)
									&& list.get(i).getLineThickness().equals(String.valueOf(diameter)) 
									&& list.get(i).getVns().equals(String.valueOf(print.getVns())))) {
								try {
									Date expDate = sdf.parse(list.get(i).getExpireDate());
									Date date = new Date();
									if (expDate.getTime() <= date.getTime()) {
										JOptionPane.showMessageDialog(null,"证书已过期！");
										print.setCertificateNo(list.get(i).getCertificateNo());
										print.setTestingAgency(list.get(i).getTestingAgency());
										// return null;
									} else {
										print.setCertificateNo(list.get(i).getCertificateNo());
										print.setTestingAgency(list.get(i).getTestingAgency());
									}
								} catch (ParseException e) {
									// TODO Auto-generated catch block
									JOptionPane.showMessageDialog(null,
											"证书匹配失敗！");
									e.printStackTrace();
								}
							} else {
								continue;
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
					print.setTypeNo(mainCode.trim());
					if(mainType=="OL35F"){
						mainType="OL35M";
					}
					print.setMainType(mainType);
					print.setPullForce(pullForce);
					print.setDiameter(diameter);
					print.setFensionForce(fensionForce);
					print.setNorm(norm);
				}
				return print;
			}

		};

		return print;
	}
}
